*******************************
*** Variables for analysis  ***
*******************************
cd "$data"
insheet using "Risktime CTB survey - May 2018_July 17, 2018_14.56.csv", names

* Drop test observations
keep if progress=="100"
drop if status!="IP Address"
drop if q122=="test" /// q122 are open comments

* Prepare Respondi IDs
* Split the url var and extract the ID 
order q_url

split q_url, parse(tic=) gen(urlsplit)

rename urlsplit2 RespondiID
drop urlsplit1
order RespondiID
label var RespondiID "Respondi DI"

* Drop remaining test observations; test period ended 1 June
drop if RespondiID==""

g day=substr(startdate,9,2)
g month=substr(startdate,6,2)
drop if day=="31" & month=="05"
drop if day=="01" & month=="06"

* Drop non-participants and people below age 18
keep if q12=="Yes" & q330=="18 or older"


* Prepare timing variables (for LOI)
order startdate enddate
rename startdate startdate_old
rename enddate enddate_old

gen double startdate = clock(startdate_old, "YMDhms")
order startdate
format startdate %tc

gen double enddate = clock(enddate_old, "YMDhms")
order enddate
format enddate %tc

gen length=minutes(enddate-startdate)
order length
format length 

* Code self-reported risk and time preferences
* Risk acceptance: 
* q111 (coding: very risk averse=1
* very risk acceptance=10)
/*Q10.1  We now ask for your willingness to act in a certain way. Please indicate your answer on a scale from 0 to 10, 
where 0 means you are ”completely unwilling to do so” and a 10 means you are ”very willing to do so”. 
You can also use any numbers between 0 and 10 to indicate where you fall on the scale, like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.     How willing are you to give up something that is beneficial for you today in order to benefit more from that in the future?    
o	Completely unwilling to do so 0   (1) 
o	1  (2) 
o	2  (3) 
o	3  (4) 
o	4  (5) 
o	5  (6) 
o	6  (7) 
o	7  (8) 
o	8  (9) 
o	9  (10) 
o	Very willing to do so 10   (11) 
*/
* q112 (coding: very risk accptance =1
* very risk averse=10)

gen q111_riskacceptant=.
replace q111_riskacceptant=0 if q111=="Completely unwilling to take risks 0 "
replace q111_riskacceptant=1 if q111=="1"
replace q111_riskacceptant=2 if q111=="2"
replace q111_riskacceptant=3 if q111=="3"
replace q111_riskacceptant=4 if q111=="4"
replace q111_riskacceptant=5 if q111=="5"
replace q111_riskacceptant=6 if q111=="6"
replace q111_riskacceptant=7 if q111=="7"
replace q111_riskacceptant=8 if q111=="8"
replace q111_riskacceptant=9 if q111=="9"
replace q111_riskacceptant=10 if q111=="Very willing to take risks 10 "
tab q111_riskacceptant

gen q112_riskacceptant=.
replace q112_riskacceptant=0 if q112=="Completely unwilling to take risks 10 "
replace q112_riskacceptant=1 if q112=="9"
replace q112_riskacceptant=2 if q112=="8"
replace q112_riskacceptant=3 if q112=="7"
replace q112_riskacceptant=4 if q112=="6"
replace q112_riskacceptant=5 if q112=="5"
replace q112_riskacceptant=6 if q112=="4"
replace q112_riskacceptant=7 if q112=="3"
replace q112_riskacceptant=8 if q112=="2"
replace q112_riskacceptant=9 if q112=="1"
replace q112_riskacceptant=10 if q112=="Very willing to take risks 0 "

gen riskacceptance_self=.
label var riskacceptance_self "Risk Acceptance (Stated)"
replace riskacceptance_self=q111_riskacceptant if q111_riskacceptant!=.
replace riskacceptance_self=q112_riskacceptant if q112_riskacceptant!=.

tab riskacceptance_self

* Code time preferences: Patience
* q101 and q102, polarity of answer scale was reversed randomly
/*
Q10.2 We now ask for your willingness to act in a certain way. 
Please indicate your answer on a scale from 0 to 10, 
where 0 means you are ”very willing to do so” and 
a 10 means you are ”completely unwilling to do so”. 
You can also use any numbers between 0 and 10 to 
indicate where you fall on the scale, 
like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. 
How willing are you to give up something that is 
beneficial for you today in order to benefit more 
from that in the future? 
o	Very willing to do so 0   (1) 
o	1  (2) 
o	2  (3) 
o	3  (4) 
o	4  (5) 
o	5  (6) 
o	6  (7) 
o	7  (8) 
o	8  (9) 
o	9  (10) 
o	Completely unwilling to do so 10   (11) 
*/

* q101 Coded from impatient (0) to patient (10)
* Recode
gen q101_patience=.
replace q101_patience=0 if q101=="Completely unwilling to do so 0 "
replace q101_patience=1 if q101=="1"
replace q101_patience=2 if q101=="2"
replace q101_patience=3 if q101=="3"
replace q101_patience=4 if q101=="4"
replace q101_patience=5 if q101=="5"
replace q101_patience=6 if q101=="6"
replace q101_patience=7 if q101=="7"
replace q101_patience=8 if q101=="8"
replace q101_patience=9 if q101=="9"
replace q101_patience=10 if q101=="Very willing to do so 10 "
tab q101_patience

* q102 Coded from impatient (10) to patient (0)
* Recode
gen q102_patience=.
replace q102_patience=0 if q102=="Completely unwilling to do so 10 "
replace q102_patience=1 if q102=="9"
replace q102_patience=2 if q102=="8"
replace q102_patience=3 if q102=="7"
replace q102_patience=4 if q102=="6"
replace q102_patience=5 if q102=="5"
replace q102_patience=6 if q102=="4"
replace q102_patience=7 if q102=="3"
replace q102_patience=8 if q102=="2"
replace q102_patience=9 if q102=="1"
replace q102_patience=10 if q102=="Very willing to do so 0 "
tab q102_patience

gen patience_self=.
label var patience_self "Patience (Stated)"
replace patience_self=q101_patience if q101_patience!=.
replace patience_self=q102_patience if q102_patience!=.

tab patience_self

* Indicator
su patience_self, det
gen patience_self_high=.
replace patience_self_high=0 if patience_self<`r(p50)'
replace patience_self_high=1 if patience_self>=`r(p50)'
label var patience_self_high "Patience Stated: High"
*** Policy measures

* Support for making effort to address climate change
tab q582
gen cceffort=.
replace cceffort=0 if q582=="No effort"
replace cceffort=1 if q582=="A small-scale effort, even if it has small economic costs"
replace cceffort=2 if q582=="A medium-scale effort, even if it has moderate economic costs"
replace cceffort=3 if q582=="A large-scale effort even if it has large economic costs"

label define cceffort_lab 0 "No effort" ///
1 "A small-scale effort, even if it has small economic costs" ///
2 "A medium-scale effort, even if it has moderate economic costs" ///
3 "A large-scale effort even if it has large economic costs"

lab values cceffort cceffort_lab
lab var cceffort "Climate Policy Effort: None, Low, Medium, High"

* Policy instruments: 1=strongly disagree to 11=strongly agree
rename q572_1 agree_cut_gh_gas_str
rename q695_1 agree_cut_gh_gas_str2
g agree_cut_gh_gas=.

rename q572_2 agree_new_tech_str
rename q695_2 agree_new_tech_str2
g agree_new_tech=.

rename q572_3 agree_cut_public_spend_str
rename q695_3 agree_cut_public_spend_str2
g agree_cut_public_spend=.

rename q572_4 agree_hum_cap_str
rename q695_4 agree_hum_cap_str2
g agree_hum_cap=.

rename q572_5 agree_cut_ss_str
rename q695_5 agree_cut_ss_str2
g agree_cut_ss=.

rename q572_6 agree_invest_ss_str
rename q695_6 agree_invest_ss_str2
g agree_invest_ss=.

rename q572_15 agree_paid_mleave_str
rename q695_15 agree_paid_mleave_str2
g agree_paid_mleave=.

rename q572_7 agree_report_wages_str
rename q695_7 agree_report_wages_str2
g agree_report_wages=.

rename q572_8 agree_sanctions_terror_str
rename q695_8 agree_sanctions_terror_str2
g agree_sanctions_terror=.

rename q572_9 agree_interventions_terror_str
rename q695_9 agree_interventions_terror_str2
g agree_interventions_terror=.

rename q572_13 agree_increase_ui_str
rename q695_13 agree_increase_ui_str2
g agree_increase_ui=.

rename q572_14 agree_ubi_str
rename q695_14 agree_ubi_str2
g agree_ubi=.

foreach x in agree_cut_gh_gas agree_new_tech agree_cut_public_spend agree_hum_cap agree_cut_ss ///
agree_invest_ss agree_paid_mleave agree_report_wages agree_sanctions_terror ///
agree_interventions_terror agree_increase_ui agree_ubi {
replace `x'=11 if `x'_str=="Strongly Agree 11" | `x'_str2=="Strongly Agree 1"
replace `x'=10 if `x'_str=="10" | `x'_str2=="2"
replace `x'=9 if `x'_str=="9" | `x'_str2=="3"
replace `x'=8 if `x'_str=="8" | `x'_str2=="4"
replace `x'=7 if `x'_str=="7" | `x'_str2=="5"
replace `x'=6 if `x'_str=="6" | `x'_str2=="6"
replace `x'=5 if `x'_str=="5" | `x'_str2=="7"
replace `x'=4 if `x'_str=="4" | `x'_str2=="8"
replace `x'=3 if `x'_str=="3" | `x'_str2=="9"
replace `x'=2 if `x'_str=="2" | `x'_str2=="10"
replace `x'=1 if `x'_str=="Strongly Disagree 1" | `x'_str2=="Strongly Disagree 11"
}

lab var agree_cut_gh_gas  "Agree should cut greenhouse gas"
lab var agree_new_tech "Agree invest in climate tech"
lab var agree_cut_public_spend "Agree should cut public spending"
lab var agree_hum_cap "Agree should invest in human capital"
lab var agree_cut_ss "Agree should cut SS spending"
lab var agree_invest_ss "Agree should invest in equities for SS"
lab var agree_paid_mleave "Agree firms should give maternity leave"
lab var agree_report_wages "Agree firms should report wages"
lab var agree_sanctions_terror "Agree should use sanctions against terror"
lab var agree_interventions_terror "Agree should use sanctions against terror"
lab var agree_increase_ui "Agree should increase UI"
lab var agree_ubi "Agree should implement UBI"

foreach x in agree_cut_gh_gas agree_new_tech agree_cut_public_spend agree_hum_cap agree_cut_ss ///
agree_invest_ss agree_paid_mleave agree_report_wages agree_sanctions_terror ///
agree_interventions_terror agree_increase_ui agree_ubi {
g `x'_dummy=(`x'>=7) if `x'!=.
}

lab var agree_cut_gh_gas_dummy  "Agree should cut greenhouse gas - dummy"
lab var agree_new_tech_dummy "Agree invest in climate tech - dummy"
lab var agree_cut_public_spend_dummy "Agree should cut public spending - dummy"
lab var agree_hum_cap_dummy "Agree should invest in human capital - dummy"
lab var agree_cut_ss_dummy "Agree should cut SS spending - dummy"
lab var agree_invest_ss_dummy "Agree should invest in equities for SS - dummy"
lab var agree_paid_mleave_dummy "Agree firms should give maternity leave - dummy"
lab var agree_report_wages_dummy "Agree firms should report wages - dummy"
lab var agree_sanctions_terror_dummy "Agree should use sanctions against terror - dummy"
lab var agree_interventions_terror_dummy "Agree should use sanctions against terror - dummy"
lab var agree_increase_ui_dummy "Agree should increase UI - dummy"
lab var agree_ubi_dummy "Agree should implement UBI - dummy"

tabstat agree_cut_gh_gas_dummy agree_new_tech_dummy agree_cut_public_spend_dummy agree_hum_cap_dummy agree_cut_ss_dummy agree_invest_ss_dummy agree_paid_mleave_dummy agree_report_wages_dummy agree_sanctions_terror_dummy agree_interventions_terror_dummy agree_increase_ui_dummy agree_ubi_dummy

* Lower threshold of 6
foreach x in agree_cut_gh_gas agree_new_tech agree_cut_public_spend agree_hum_cap agree_cut_ss ///
agree_invest_ss agree_paid_mleave agree_report_wages agree_sanctions_terror ///
agree_interventions_terror agree_increase_ui agree_ubi {
g `x'_d6=(`x'>=6) if `x'!=.
}

lab var agree_cut_gh_gas_d6  "Agree should cut greenhouse gas - dummy"
lab var agree_new_tech_d6 "Agree invest in climate tech - dummy"
lab var agree_cut_public_spend_d6 "Agree should cut public spending - dummy"
lab var agree_hum_cap_d6 "Agree should invest in human capital - dummy"
lab var agree_cut_ss_d6 "Agree should cut SS spending - dummy"
lab var agree_invest_ss_d6 "Agree should invest in equities for SS - dummy"
lab var agree_paid_mleave_d6 "Agree firms should give maternity leave - dummy"
lab var agree_report_wages_d6 "Agree firms should report wages - dummy"
lab var agree_sanctions_terror_d6 "Agree should use sanctions against terror - dummy"
lab var agree_interventions_terror_d6 "Agree should use sanctions against terror - dummy"
lab var agree_increase_ui_d6 "Agree should increase UI - dummy"
lab var agree_ubi_d6 "Agree should implement UBI - dummy"

* Ladder, nets, walls question
*fre q690, width(100)
g approach_trade=1 if q690=="The federal government should implement policies that reduce international trade, prevent firms from going overseas, and decrease immigration. Even if globalization is good for the economy overall, it hurts regular people too much and should be limited."
replace approach_trade=2 if q690=="The federal government should encourage international trade, foreign investment, and immigration to increase economic growth. But it should also adopt new policies that substantially tax those firms and individuals that benefit from globalization and then spend the new revenue on government income programs for everyone else."
replace approach_trade=3 if q690=="The federal government should encourage international trade, foreign investment and immigration to increase economic growth. But it should also adopt new policies that substantially tax those firms and individuals that benefit from globalization and then spend the new revenue on programs—for example, training and education—that provide more people with greater opportunity to benefit from globalization."

lab var approach_trade "Approach to international trade"
lab def trade 1 "Walls" 2 "Nets" 3 "Ladder"
lab val approach_trade trade  


*** Sociodemographics
* Age
destring q701, replace
g age=2018-q701
g age1834=(age>=18 & age<=34)
label var age1834 "Age: 18-34" 
g age3549=(age>=35 & age<=49)
label var age1834 "Age: 35-49" 
g age5064=(age>=50 & age<=64)
label var age5064 "Age: 50-64" 
g age65above=(age>=65 & age!=.)
label var age65above "Age: 65+"

g agegroups=.
replace agegroups=1 if age1834==1
replace agegroups=2 if age3549==1
replace agegroups=3 if age5064==1
replace agegroups=4 if age65above==1

lab define agegroups 1 "18-34" 2 "35-49" 3 "50-64" 4 "65+"
lab values agegroups agegroups

lab var age "Age"

* Race
g white=(q85=="White")
lab var white "White"

lab define white_lab 0 "Non-White" 1 "White"
lab values white white_lab

tab q85


* Gender
g female=0
replace female=1 if q86=="Female"
lab var female "Female"

lab define female_lab 0 "Male" 1 "Female"
lab values female female_lab

g male=0
replace male=1 if q86=="Male"
lab var male "Male"

lab define male_lab 0 "Female" 1 "Male"
lab values male male_lab

* Gender levels including "other"
g gender=.
replace gender=1 if q86=="Male"
replace gender=2 if q86=="Female"
replace gender=3 if q86=="Other"

lab define gender_lab 1 male 2 female 3 other
lab values gender gender_lab

* Education
/*
q84
1	No schooling completed, or less than 1 year	0.09%	4
2	Nursery, kindergarten, and elementary (grades 1-8)	0.28%	13
3	High school (grades 9-12, no degree)	3.36%	156
4	High school graduate (or equivalent)	23.31%	1081
5	Some college (1-4 years, no degree)	26.07%	1209
6	Associate’s degree (including occupational or academic degrees)	13.97%	648
7	Bachelor’s degree (BA, BS, AB, etc)	20.92%	970
8	Master’s degree (MA, MS, MENG, MSW, etc)	9.27%	430
9	Professional school degree (MD, DDC, JD, etc)	1.51%	70
10	Doctorate degree (PhD, EdD, etc)	1.21%	56
*/

* Coding for education dummies
* Code less than HS
g less_than_hs=0

* Less than HS include:
* No schooling
replace less_than_hs=1 if q84=="No schooling completed, or less than 1 year"
* Nursery etc
replace less_than_hs=1 if q84=="Nursery, kindergarten, and elementary (grades 1-8)"
* High school no degree
replace less_than_hs=1 if q84=="High school (grades 9-12, no degree)"

lab var less_than_hs "Less than HS"

* Code HS
g hs=0
replace hs=1 if q84=="High school graduate (or equivalent)"

lab var hs "HS Graduate"

* Code some college or associate degree
g some_college=0
replace some_college=1 if q84=="Some college (1-4 years, no degree)"
replace some_college=1 if q84=="Associate’s degree (including occupational or academic degrees)"

lab var some_college "Some College"

* Code BA or more
g ba_or_more=0
replace ba_or_more=1 if q84=="Bachelor’s degree (BA, BS, AB, etc)"
replace ba_or_more=1 if q84=="Master’s degree (MA, MS, MENG, MSW, etc)"
replace ba_or_more=1 if q84=="Professional school degree (MD, DDC, JD, etc)"
replace ba_or_more=1 if q84=="Doctorate degree (PhD, EdD, etc)"

lab var ba_or_more "BA or more"

* Generate education level variable
g educ=1 if less_than_hs==1
replace educ=2 if hs==1
replace educ=3 if some_college==1
replace educ=4 if ba_or_more==1

lab def educ 1 "Less than HS" 2 "HS" 3 "Some College" 4 "BA or more" 
lab val educ educ


* Gender
* Population margins
* : Sex: male: 49 %, female: 51
tab gender

* Population margins
* Age: 
* 18-34: 30 %
* 35-49: 25 %
* 50-64: 25 %
* 65+: 20 %
tab agegroups

*tab age1834
*tab age3549
*tab age5064
*tab age65above

* Education: less than HS: 12 %, HS: 28 %, some college: 31 %, BA or more: 29 %
* Target frequency (N=5,000)
* less than HS: 600, 
* HS: 1,400
* some college: 1,550
* BA or more: 1,450

tab educ
******

tab white

* Income
* q88: income
tab q88
gen income=.
replace income=1 if q88=="$10,000 - $19,999"
replace income=2 if q88=="$20,000 - $29,999"
replace income=3 if q88=="$30,000 - $39,999"
replace income=4 if q88=="$40,000 - $54,999"
replace income=5 if q88=="$55,000 - $69,999"
replace income=6 if q88=="$70,000 - $84,999"
replace income=7 if q88=="$85,000 - $99,999"
replace income=8 if q88=="$100,000 - $124,999"
replace income=9 if q88=="$125,000 - $149,999"
replace income=10 if q88=="$150,000 - $174,999"
replace income=11 if q88=="$175,000 - $199,999"
replace income=12 if q88=="$200,000 - $249,999"
replace income=13 if q88=="$250,000 - $349,999"
replace income=14 if q88=="$350,000 - $470,000"
replace income=15 if q88=="Over $470,000"
su income, det

lab define income_lab ///
1 "$10,000 - $19,999" ///
2 "$20,000 - $29,999" ///
3 "$30,000 - $39,999" ///
4 "$40,000 - $54,999" ///
5 "$55,000 - $69,999" ///
6 "$70,000 - $84,999" ///
7 "$85,000 - $99,999" ///
8 "$100,000 - $124,999" ///
9 "$125,000 - $149,999" ///
10 "$150,000 - $174,999" ///
11 "$175,000 - $199,999" ///
12 "$200,000 - $249,999" ///
13 "$250,000 - $349,999" ///
14 "$350,000 - $470,000" ///
15 "Over $470,000"

lab values income income_lab
tab income 

* Generate quintile groups
recode income (1/2=1) (3/4=2) (5/6=3) (7/15=4), gen(inc_group)
lab define inc_group_lab 1 "Income: Low" 2 "Income: Lower Middle" 3 "Income: Upper Middle" 4 "Income: High"
label values inc_group inc_group_lab
label var inc_group "Income Groups"
tab inc_group, gen(inc_)

rename inc_1 inc_low
label var inc_low "Income: Low"
rename inc_2 inc_lmiddle
label var inc_low "Income: Lower Middle"
rename inc_3 inc_umiddle
label var inc_umiddle "Income: Upper Middle"
rename inc_4 inc_high
label var inc_high "Income: High"

tab inc_group


* Ideology: q713: lrideo (0 to 10)
tab q713
gen lrideo=.
replace lrideo=0 if q713=="Left0"
replace lrideo=1 if q713=="1"
replace lrideo=2 if q713=="2"
replace lrideo=3 if q713=="3"
replace lrideo=4 if q713=="4"
replace lrideo=5 if q713=="5"
replace lrideo=6 if q713=="6"
replace lrideo=7 if q713=="7"
replace lrideo=8 if q713=="8"
replace lrideo=9 if q713=="9"
replace lrideo=10 if q713=="Right10"
su lrideo, det

* Code ideology groups: far left, left, middle, right, far right
recode lrideo (0/2=0) (3/4=1) (5=2) (6/7=3) (8/10=4), gen(lrideo_groups)
lab var lrideo_groups "Ideology"
label define lrideo_groups_lab 0 "Ideology: Far Left" 1 "Ideology: Left" 2 "Ideology: Middle" 3 "Ideology: Right" 4 "Ideology: Far Right"
lab values lrideo_groups lrideo_groups_lab
tab lrideo_groups, gen(lrideo_gr)

su lrideo, det
* Code ideology groups: left middle right
recode lrideo (0/4=1) (5/7=2) (8/10=3), gen(lrideo_3groups)
lab var lrideo_3groups "Ideology"
label define lrideo_groups_3lab 1 "Ideology: Left" 2 "Ideology: Middle" 3 "Ideology: Right"
lab values lrideo_3groups lrideo_groups_3lab
tab lrideo_3groups, gen(lrideo_)

rename lrideo_1 ideo_left
label var ideo_left "Ideology: Left"
rename lrideo_2 ideo_middle
label var ideo_middle "Ideology: Middle"
rename lrideo_3 ideo_right
label var ideo_right "Ideology: Right"


* Partisan identification: q91 Democrat, Republican, Independent
tab q91
gen partyid=.
replace partyid=1 if q91=="Democrat"
replace partyid=2 if q91=="Independent"
replace partyid=3 if q91=="Republican"
replace partyid=4 if q91=="Other"

tab partyid, gen(partyid_gr)
rename partyid_gr1 democrat
label var democrat "Democrat"

rename partyid_gr2 independent
label var independent "Independent"

rename partyid_gr3 republican
label var republican "Republican"

gen rep_vs_demo=.
replace rep_vs_demo=0 if democrat==1
replace rep_vs_demo=1 if republican==1
label var rep_vs_demo "Republican (vs. Democrat)"
label define repvsdemo 0 Democrat 1 Republican
label values rep_vs_demo repvsdemo

* Recoded Party ID
recode partyid (1=1) (2=3) (3=2) (4=4) (else=.), gen(party_rec)
label define party_lab 1 "Democrat" 2 "Republican" 3 "Independent" 4 "Other"
label values party_rec party_lab
label var party_rec "Party Identification"
/* Treatment and demographics
global demo "age1834 age3549 age5064 female white hs some_college ba_or_more"
reg ctb $demo
reg ctb1 $demo
reg ctb2 $demo
reg ctb3 $demo
reg ctb4 $demo
*/

*** Weights
/* Population margins
Sex: male: 49 %, female: 51 %
Age: 18-34: 30 %, 35-49: 25 %, 50-64: 25 %, 65 and above: 20 %
Education: less than HS: 12 %, HS: 28 %, some college: 31 %, BA or more: 29 %
*/

* Weights for full sample (CTB sample is smaller)
ebalance ib4.educ ib4.agegroups female, manual(0.12 0.28 0.31 0.3 0.25 0.25 0.51) gen(weights_full_sample)

*** Check weights (and trade question from cities project)
tab female
tab female [aweight=weights_full_sample]

tab educ
tab educ [aweight=weights_full_sample]

tab agegroups
tab agegroups [aweight=weights_full_sample]

tab approach_trade
tab approach_trade [aweight=weights_full_sample]

* Walls: 28.7 %, Walls weighted: 29.3
* Nets: 26.0 %, Nets weighted: 25.8
* Ladder: 45.3 %, Ladder weighted: 44.9

* Explore variation on time preference measures
forvalues i=1/31 {
encode t`i', gen(tp_`i')
lab var tp_`i' "Payment today/in 12 months (Q`i')"
tab tp_`i'
}

forvalues i=1/31 {
encode r`i', gen(rp_`i')
lab var rp_`i' "Sure payment/lottery (Q`i')"
tab rp_`i'
}

* Policy salience: Points
* q289_1: climate change
destring q289_1, gen(sal_climatechange)
label var sal_climatechange "Salience: Climate Change"
* q289_2: public debt
destring q289_2, gen(sal_publicdebt)
label var sal_publicdebt "Salience: Public Debt"
* q289_3: social security
destring q289_3, gen(sal_socialsecurity)
lab var sal_socialsecurity "Salience: Social Security"

*q289_4: Gender equality
destring q289_4, gen(sal_genderequality)
lab var sal_genderequality "Salience: Gender Equality"
* q289_5: International terrorism
destring q289_5, gen(sal_intlterrorism)
lab var sal_intlterrorism "Salience: International Terrorism"
*q289_6: Care for the unemployed and underemployed
destring q289_6, gen(sal_careunemployed)
lab var sal_careunemployed "Salience: Care for Unemployed"
order sal*

* Completion time
foreach x of varlist *_pagesubmit *_clickcount *_lastclick *_firstclick durationinseconds {
qui destring `x', replace
}

egen pagesubmit_ctb_mean=rmean(*_pagesubmit)
egen clicks_ctb_mean=rmean(*_clickcount)
egen lastclick_ctb_mean=rowmean(*_lastclick)
egen firstclick_ctb_mean=rowmean(*_firstclick)
g durationminutes=durationinseconds/60

tabstat pagesubmit_ctb_mean, s(mean median min max sd)
tabstat clicks_ctb_mean, s(mean median min max sd)
tabstat lastclick_ctb_mean, s(mean median min max sd)
tabstat firstclick_ctb_mean, s(mean median min max sd)
tabstat durationinseconds, s(mean median min max sd)
tabstat durationminutes, s(mean median min max sd)

* q121: Questionnaire quality rating
* 9 = Excellent
* 1 = Poor
gen surveyrating=q121
replace surveyrating="1" if surveyrating=="1 = Poor"
replace surveyrating="9" if surveyrating=="9 = Excellent"
destring surveyrating, replace
su surveyrating, det

* CTB treatments
* Generate treatment indicators
* CTB 1: everyone has 1/24 decisions paid out
g ctb1=(q35!="") 

* CTB 2: 1/5 have 1/24 decisions paid out
g ctb2=(q511!="")

* CTB 3: Hypothetical low payments
g ctb3=(q542!="")

* CTB 4: Hypothetical high payments
g ctb4=(q476!="")

* Generate treatment factor variable
* Use order that makes sense: Low stakes, high stakes,...
g ctb=1 if ctb1==1
replace ctb=2 if ctb2==1
replace ctb=3 if ctb3==1
replace ctb=4 if ctb4==1
tab ctb // 25 % in each

* Label var and gen value label 
label var ctb "Treatment Condition"

lab define ctb_lab 1 "Benchmark CTB" 2 "CTB Lottery" 3 "CTB Hypothetical Low" 4 "CTB Hypothetical High"
lab values ctb ctb_lab
tab ctb

* Generate binary indicators
* separating treatment group from others
gen D_ctblottery=0
replace D_ctblottery=0 if ctb==1
replace D_ctblottery=1 if ctb==2 
label var D_ctblottery "Lottery"

gen D_ctbhyplow=0
replace D_ctbhyplow=0 if ctb==1
replace D_ctbhyplow=1 if ctb==3 
label var D_ctbhyplow "Hypothetical Low"

gen D_ctbhyphi=0
replace D_ctbhyphi=0 if ctb==1
replace D_ctbhyphi=1 if ctb==4 
label var D_ctbhyphi "Hypothetical High"

* separating benchmark CTB and treatment group
gen ctblottery_D=.
replace ctblottery_D=0 if ctb==1
replace ctblottery_D=1 if ctb==2 

gen ctbhyplow_D=.
replace ctbhyplow_D=0 if ctb==1
replace ctbhyplow_D=1 if ctb==3 

gen ctbhyphi_D=.
replace ctbhyphi_D=0 if ctb==1
replace ctbhyphi_D=1 if ctb==4 

* Generate binary indicators
* separating lottery and hypo low and hypo high
gen ctblottery_hypolow_D=.
replace ctblottery_hypolow_D=0 if ctb==2
replace ctblottery_hypolow_D=1 if ctb==3 

gen ctblottery_hypohigh_D=.
replace ctblottery_hypohigh_D=0 if ctb==2
replace ctblottery_hypohigh_D=1 if ctb==4 

* Generate binary indicator
* separating hypo low and hypo high
gen ctbhypolow_hypohigh_D=.
replace ctbhypolow_hypohigh_D=0 if ctb==3
replace ctbhypolow_hypohigh_D=1 if ctb==4 

* Generate interactions between sociodemographics and political vars

foreach group in republican independent democrat ideo_right ideo_middle ideo_left { 	
	foreach var in age age3549 age5064 age65above educ hs some_college ba_or_more inc_low inc_lmiddle inc_umiddle inc_high income {
	gen `group'X`var'=`group'*`var'	
	}
}

sort responseid
compress
save "$user/02 Data/variables_foranalysis", replace



